package io.renren.modules.jxgk.service.impl;

import io.renren.modules.jxgk.entity.EvaluationTimeTeacherEntity;
import io.renren.modules.jxgk.service.EvaluationTimeTeacherService;
import io.renren.modules.jxgk.dao.EvaluationTimeDao;
import io.renren.modules.jxgk.entity.EvaluationTimeEntity;
import io.renren.modules.jxgk.service.EvaluationTimeService;
import io.renren.modules.jxgk.utils.UUidCreater;
import io.renren.modules.jxgkphone.entity.ClassCourse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class EvaluationTimeServiceImpl implements EvaluationTimeService{
    @Autowired
    EvaluationTimeDao evaluationTimeDao;
    @Autowired
    EvaluationTimeTeacherService evaluationTimeTeacherService;

    public List<EvaluationTimeEntity> queryList(Map<String, Object> map){
        return evaluationTimeDao.queryList(map);
    }
    public int queryTotal(Map<String, Object> map){
        return  evaluationTimeDao.queryTotal(map);
    }
    public void deleteBatch(String[] termIds){
        evaluationTimeDao.deleteBatch(termIds);
    }
    public void save(EvaluationTimeEntity ste){
        evaluationTimeDao.save(ste);
        String evaluationId=evaluationTimeDao.queryByTime(ste.getEvaluationStartDate(),ste.getEvaluationEndDate());
        List<ClassCourse> evaluableTeacher=evaluationTimeDao.evaluableTeacherInfo(ste.getEvaluationStartDate(),ste.getEvaluationEndDate());
        for(ClassCourse cc:evaluableTeacher){
            String uuid=UUidCreater.getUUID();
            EvaluationTimeTeacherEntity ETTE=new EvaluationTimeTeacherEntity();
            ETTE.setEvaluationTimeTeacherId(uuid);
            ETTE.setEvaluable("1");
            ETTE.setEvaluationTeacherId(cc.getCourseTeacherId());
            ETTE.setEvaluationTeacherName(cc.getCourseTeacherName());
            ETTE.setEvaluationTimeId(evaluationId);
            evaluationTimeTeacherService.save(ETTE);
        }
    }
    public EvaluationTimeEntity queryObject(String index){
        return evaluationTimeDao.queryObject(index);
    }
    public void update(EvaluationTimeEntity ste){
        evaluationTimeDao.update(ste);
    }
    public List<String> valid(String date){

        UUidCreater u=new UUidCreater();
        List<EvaluationTimeEntity> evaluationTimeEntities=evaluationTimeDao.ValidTime();
        for(EvaluationTimeEntity e:evaluationTimeEntities){
            String start=e.getEvaluationStartDate();
            String end=e.getEvaluationEndDate();
            if(u.compare_date(start,date)==-1&&u.compare_date(date,end)==-1){
                String id=e.getEvaluationTimeId();
                List<String> teacherList=evaluationTimeDao.ValidTeacherId(id);
                return teacherList;
            }
        }
        return null;
    }
}
